
<table id="datagrid_${action_id}" ></table>
<div id="datagrid_${action_id}_tb" style="padding:5px;height:auto">
	<select class="easyui-combobox" style="width: 150px;" data-options="onChange:function(nv,ov){
		$('#datagrid_${action_id}').datagrid('options').queryParams = {id:nv};
		$('#datagrid_${action_id}').datagrid('reload');
		model_fieldproperty_${action_id} = nv;
	}"  >
		<#list applications as app>
		<option value="${app.id?default('')}" >${app.title}</option>
		</#list>
	</select>
	<a href="javascript:clone_${action_id}();" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" >复制</a>
	<a href="javascript:refresh_${action_id}();" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" >${action.getText('bg.message.refesh')}</a>
</div>
<script type="text/javascript">

var editIndex_${action_id} = undefined;

var field_${action_id} =[];

var model_fieldproperty_${action_id};

$(function(){
	
	$('#datagrid_${action_id}').datagrid({
		iconCls:'icon-save',
		width:'auto',
		height:'auto',
		nowrap: false,
		fit:true,
		fitColumns:true,
		striped: true,
		url:'${request.contextPath}${namespace?default('')}/mp/sysres/fieldproperty-datagrid.json',
		sortName: 'id',
		sortOrder: 'desc',
		remoteSort: true,
		singleSelect : true,
		idField:'id',
		onBeforeLoad:function(){$('#datagrid_${action_id}').datagrid('unselectAll');},
		columns:[[
					{field:'url',title:'${action.getDatagridTitle('url')}',width:150,align:'center'},
					{field:'propertyId',title:'${action.getDatagridTitle('propertyId')}',width:150,align:'center'},
					{field:'add',title:'${action.getDatagridTitle('add')}',width:50,align:'center',editor:{type:'checkbox',options:{on:true,off:false}}},
					{field:'edit',title:'${action.getDatagridTitle('edit')}',width:50,align:'center',editor:{type:'checkbox',options:{on:true,off:false}}},
					{field:'view',title:'${action.getDatagridTitle('view')}',width:50,align:'center',editor:{type:'checkbox',options:{on:true,off:false}}},
					{field:'list',title:'${action.getDatagridTitle('list')}',width:50,align:'center',editor:{type:'checkbox',options:{on:true,off:false}}},
					{field:'sort',title:'${action.getDatagridTitle('sort')}',width:50,align:'center',editor:{type:'checkbox',options:{on:true,off:false}}},
					{field:'defaults',title:'${action.getDatagridTitle('defaults')}',width:200,align:'center',editor:'text'}
				]],
		pagination:false,
		rownumbers:true,
		toolbar:'#datagrid_${action_id}_tb',
		onClickCell:function onClickCell(index, field,value){
			var node = $('#datagrid_${action_id}').datagrid('selectRow', index).datagrid('getSelected');
			if(!node){
				return;
			}
			var edab = node.editable;
			switch(field){
			case 'add':
				if((edab&0x10)==0){
					return;
				}
				break;
			case 'edit':
				if((edab&0x08)==0){
					return;
				}
				break;
			case 'view':
				if((edab&0x04)==0){
					return;
				}
				break;
			case 'list':
				if((edab&0x02)==0){
					return;
				}
				break;
			case 'sort':
				if((edab&0x01)==0){
					return;
				}
				break;
			}			
			if (endEditing_${action_id}()){
				$('#datagrid_${action_id}').datagrid('selectRow', index)
						.datagrid('editCell', {index:index,field:field});
				editIndex_${action_id} = index;
			}
		},
		/*onClickRow: function(index,data){
			var editors = $('#datagrid_${action_id}').datagrid('getEditors', index);
			$.each(editors,function(i,e){
				$(e.target).attr('disable','true');
			});
			if (editIndex_${action_id} != index){
				if (endEditing_${action_id}()){
					$('#datagrid_${action_id}').datagrid('selectRow', index)
							.datagrid('beginEdit', index);
					editIndex_${action_id} = index;
				} else {
					$('#datagrid_${action_id}').datagrid('selectRow', editIndex);
				}
			}
		},*/
		onAfterEdit:function(index,data,changes){
			$.post('${request.contextPath}${namespace?default('')}/mp/sysres/fieldproperty-update.json',{'entity.id':data.id,'entity.add':data.add,'entity.edit':data.edit,'entity.view':data.view,'entity.list':data.list,'entity.sort':data.sort,'entity.defaults':data.defaults},function(json){
				if(json.level=='error'){
					$.messager.alert(json.title,json.msg,json.level);
				}
			});
		}
	});

});

function endEditing_${action_id}(){
	if (editIndex_${action_id} == undefined){return true}
	if ($('#datagrid_${action_id}').datagrid('validateRow', editIndex_${action_id})){
		$('#datagrid_${action_id}').datagrid('endEdit', editIndex_${action_id});
		editIndex_${action_id} = undefined;
		return true;
	} else {
		return false;
	}
}

function refresh_${action_id}(){
	$.post('${request.contextPath}${namespace?default('')}/mp/sysres/fieldproperty-refresh.json',{},function(json){
		$('#datagrid_${action_id}').datagrid('reload');
	});
}

function clone_${action_id}(){
	if(model_fieldproperty_${action_id}==undefined){
		return;
	}
	$.messager.prompt('', 'Please type clone url', function(u){
		if (u){
			$.post('${request.contextPath}${namespace?default('')}/mp/sysres/fieldproperty-clonep.json',{id:model_fieldproperty_${action_id},u:u},function(json){
				$('#datagrid_${action_id}').datagrid('reload');
			});
		}
	});
}

</script>	